package com.resou.reader.bookstore.rank;

import com.resou.reader.api.ApiImp;
import com.resou.reader.api.entry.ChannelBean;
import com.resou.reader.api.entry.RankTypeBean;
import com.resou.reader.api.entry.Result;
import com.resou.reader.api.service.StoreService;
import com.resou.reader.base.ResouBasePresenter;
import com.resou.reader.base.m.IModel;

import java.util.ArrayList;
import java.util.List;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

/**
 * Author: 萤火虫
 * E-mail:  Allensuns@163.com
 * Description:
 * CreateTime: 2019-04 -09
 */
public class RankPresenter extends ResouBasePresenter<IRankContract.IRankView> implements IRankContract.IRankPresenter {
    StoreService storeService;

    public RankPresenter(IRankContract.IRankView view) {
        super(view);
        storeService = ApiImp.getInstance().getService(StoreService.class);
    }

    @Override
    public void quearChannel() {
        mView.showProgress();
        storeService.rankChannel().subscribeOn(getIOSchedulers())
                .observeOn(getMainSchedulers())
                .subscribe(new Observer<Result<List<ChannelBean>>>() {
                    @Override
                    public void onSubscribe(Disposable d) {
                        addCompositeDisposable(d);
                    }

                    @Override
                    public void onNext(Result<List<ChannelBean>> listResult) {
                        mView.showChannel(listResult.getData());
                    }

                    @Override
                    public void onError(Throwable e) {
                        mView.showContent();
                        mView.showError(e);
                    }

                    @Override
                    public void onComplete() {
                        mView.showContent();

                    }
                });
    }
}
